<!DOCTYPE html>
<html>
<head>
<script src='../../../resources/testharness.js'></script>
<script src='../../../resources/testharnessreport.js'></script>
<script src='../../../fast/forms/resources/picker-common.js'></script>
</head>
<body>
<input type='color' id='color' value='#3d5a66'>
<script>
'use strict';

promise_test(() => {
  let colorControl = document.getElementById('color');
  return openPickerWithPromise(colorControl)
  .then(() => {
    internals.pagePopupWindow.focus();
    const popupDocument = internals.pagePopupWindow.document;
    const colorWell = popupDocument.querySelector('color-well');
    const colorWellRect = colorWell.getBoundingClientRect();
    eventSender.mouseMoveTo(colorWellRect.left + (colorWellRect.width * 2 / 10), colorWellRect.top + (colorWellRect.height * 3 / 10));
    eventSender.mouseDown();
    eventSender.mouseUp();
    assert_equals(colorControl.value, '#8fa8b3', 'Mouse input should have changed color value.');

    eventSender.mouseMoveTo(colorWellRect.left + (colorWellRect.width * 4 / 10), colorWellRect.top + (colorWellRect.height * 6 / 10));
    eventSender.mouseDown();
    eventSender.mouseUp();
    assert_equals(colorControl.value, '#3d5a66', 'Mouse input should have changed color back to original value.');
    eventSender.keyDown('Escape');
    assert_equals(internals.pagePopupWindow, null, 'Single escape should change popup since its value was switched back the value when opened');
  });
}, "Color picker: Pressing escape closes popup after value is changed and then set back to original value.");

</script>
</body>
</html>
